import MySQLdb
import const as Const
from DBUtils.PooledDB import PooledDB

class DBManager:

    def __init__(self):
        connkwargs = {
            'host': Const.MYSQL_CONFIG['HOST'],
            'user': Const.MYSQL_CONFIG['USER'],
            'port': Const.MYSQL_CONFIG['PORT'],
            'passwd': Const.MYSQL_CONFIG['PASSWORD'],
            'db': Const.MYSQL_CONFIG['NAME'],
            'charset': "utf8"
        }
        self._pool = PooledDB(MySQLdb, mincached=0, maxcached=10, maxshared=10, maxusage=10000, **connkwargs)

    def getConn(self):
        return self._pool.connection()
